package cst.a328zf.startproject_328zf;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cst.a328zf.startproject_328zf.bean.WeatherInfo;
import cst.a328zf.startproject_328zf.bean.WeatherResult;
import cst.a328zf.startproject_328zf.listener.WeatherListener;
import cst.a328zf.startproject_328zf.model.Weather51Model;
import cst.a328zf.startproject_328zf.model.WeatherModel;

public class MainActivity extends AppCompatActivity {
    private EditText cityNOInput;
    private Button[] btn=new Button[2];//btn_1,btn_2;
    private TextView city_text,fs_text,fx_text;
    private TextView wd_text;
    private WeatherModel model;
    private Weather51Model model2;

    private WeatherListener listener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cityNOInput = (EditText) findViewById(R.id.cityNOInput);
       // btn_1 = (Button)findViewById(R.id.btn_1);
        //btn_2 = (Button)findViewById(R.id.btn_2);
        btn[0]=(Button)findViewById(R.id.btn_1);
        btn[1]=(Button)findViewById(R.id.btn_2);
        city_text = (TextView)findViewById(R.id.city_text);
        wd_text = (TextView)findViewById(R.id.wd_text);
        fs_text = (TextView)findViewById(R.id.fs_text);
        fx_text = (TextView)findViewById(R.id.fx_text);

        listener=new WeatherListener() {
            @Override
            public void onResponse(WeatherInfo w) {
                city_text.setText(w.getCity());
                wd_text.setText(w.getTemp());
                fx_text.setText(w.getWD());
                fs_text.setText(w.getWS());
            }
            @Override
            public void onFail(String msg) {
                city_text.setText("解析错误");


            }

        };


          btn[0].setOnClickListener(new TextView.OnClickListener() {

                @Override
                public void onClick(View v) {
                    model = new WeatherModel();
                    model.getWeather(cityNOInput.getText().toString(), listener);
                }
            });


            btn[1].setOnClickListener(new TextView.OnClickListener() {

                @Override
                public void onClick(View v) {
                    model2 = new Weather51Model();
                    model2.getWeather(cityNOInput.getText().toString(),listener);
                }
            });

          }

    }



